var express = require("express");
var router = express.Router();
var db = require("../db/index");

router.post('/add', function (req, res, next) {
  let {type,content,user_id,feedback_time,society_id} = req.body;
  db.query(`INSERT INTO feedback set ?`, {
    type,content,user_id,feedback_time,society_id
  }, function (err) {
    if (!err) {
      res.send({
        code: 200,
        message: '成功'
      })
    } else {
      res.send({
        code: 20009,
        message: err.message
      })
    }
  })
})

router.get('/info',function (req,res) {
  let {society_id,pageNo,limit} = req.query;
  let start = (pageNo-1)*limit;
  let sql = `select f.*,a.name from feedback f JOIN account a ON f.user_id=a.id where f.society_id = ${society_id} ORDER BY f.id DESC LIMIT ${start},${limit}`
  db.query(sql,function (err,rows) {
    if (!err) {
      res.send({
        code: 200,
        message: '成功',
        feedback:rows
      })
    } else {
      res.send({
        code: 20009,
        message: err.message
      })
    }
  })
})


module.exports = router;
